import { defineConfig, type PluginOption, type ProxyOptions } from "vite";
import vue from "@vitejs/plugin-vue";
import vueDevTools from "vite-plugin-vue-devtools";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
// import { fileURLToPath } from "url";
import { resolve } from "path";

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue() as PluginOption,
    vueDevTools() as PluginOption,
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }) as PluginOption,
    Components({
      resolvers: [
        ElementPlusResolver({
          importStyle: "css", //强制导入组件样式
          directives: true, //包含指令样式
        }),
      ],
    }) as PluginOption,
  ],
  resolve: {
    alias: {
      // "@": fileURLToPath(new URL("./src", import.meta.url)),
      "@": resolve(__dirname, "./src"),
      "*": resolve(""),
    },
  },
  server: {
    proxy: {
      "/dsod": {
        target: "http://47.109.203.113:8080",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/dsod/, "/dsod"),
      } as ProxyOptions,
      "/ai": {
        target: "http://47.109.203.113:8080",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/ai/, "/ai"),
      } as ProxyOptions,
    },
  },
});
